/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Test;

import SecureUtil.Packer;
import java.util.Arrays;

/**
 *
 * @author agener
 */
public class PackerTest {
    public static void main(String[] argv){
    try{
        Packer p = new Packer();
        String e1 = "I am test string";
        byte[] e2 = "I am test byte array".getBytes();
        int e3 = 100;
        byte e4 = 't';
        byte[] e5 = "I am test bytearray too".getBytes();

        p.addElement(Packer.DataType.STRING, e1);
        p.Reset();
        p.addElement(Packer.DataType.STRING, e1);
        p.addElement(Packer.DataType.BYTES, e2);
        p.addElement(Packer.DataType.INTEGER, e3);
        p.addElement(Packer.DataType.BYTE, e4);
        p.addElement(Packer.DataType.BYTES, e5);

        byte[] packed = p.pack();

        // unpack start;
        p.unpack(packed);
        String t1 = (String)p.getNext(Packer.DataType.STRING);
        byte[] t2 = (byte[]) p.getNext(Packer.DataType.BYTES);
        int t3 = (Integer) p.getNext(Packer.DataType.INTEGER);
        byte t4 = (Byte) p.getNext(Packer.DataType.BYTE);
        byte[] t5 = (byte[]) p.getNext(Packer.DataType.BYTES);

        
        System.out.println(e1+":"+t1);
        System.out.println(e2.toString()+":"+t2.toString());
        System.out.println(""+e3+":"+t3);
        System.out.println(""+e4+":"+t4);
        //System.out.println(e5.toString()+":"+t5.toString());

        if(e1.equals(t1)) System.out.println("String e1 = t1");
        else System.out.println("test failed: String e1 = t1");
        if(Arrays.equals(e2, t2)) System.out.println("Byte Array e2 = t2");
        else System.out.println("test failed: Byte Array e2 = t2");
        if(e3==t3) System.out.println("int e3 = t3");
        else System.out.println("test failed: int e3 = t3");
        if(e4==t4) System.out.println("byte e4 = t4");
        else System.out.println("test failed: byte e4 = t4");
        if(Arrays.equals(e5,t5)) System.out.println("byte array e5 = t5");
        else System.out.println("test failed: byte array e5 != t5");

    }catch(Exception e){
        e.printStackTrace();
    }
    }
}
